package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusPost;
import com.ruoyi.business.service.IBusPostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位管理Controller
 * 
 * @author ling
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/business/post")
public class BusPostController extends BaseController
{
    @Autowired
    private IBusPostService busPostService;
    @Value("${export.max:10000}")
    private Integer max;

    /**
     * 查询岗位管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:post:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusPost busPost)
    {
        startPage();
        List<BusPost> list = busPostService.selectBusPostList(busPost);
        return getDataTable(list);
    }


    /**
     * 导出岗位管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:post:export')")
    @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusPost busPost)
    {
        List<BusPost> list = busPostService.selectBusPostList(busPost);
        if (list.size() > max) {
            throw new ServiceException("导出失败！,每次最多导出 " + max + "条");
        }
        ExcelUtil<BusPost> util = new ExcelUtil<BusPost>(BusPost.class);
        util.exportExcel(response, list, "岗位管理数据");
    }

    /**
     * 获取岗位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:post:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busPostService.selectBusPostById(id));
    }

    /**
     * 新增岗位管理
     */
    @PreAuthorize("@ss.hasPermi('business:post:add')")
    @Log(title = "岗位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusPost busPost)
    {
        return toAjax(busPostService.insertBusPost(busPost));
    }

    /**
     * 修改岗位管理
     */
    @PreAuthorize("@ss.hasPermi('business:post:edit')")
    @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusPost busPost)
    {
        return toAjax(busPostService.updateBusPost(busPost));
    }

    /**
     * 删除岗位管理
     */
    @PreAuthorize("@ss.hasPermi('business:post:remove')")
    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busPostService.deleteBusPostByIds(ids));
    }
}
